<?php
namespace PackageSpy;
use Nette;
class PackageModel extends Nette\Object
{
	protected $connection;
	
	public function __construct(Nette\Database\Connection $db)
	{
		$this->connection = $db;
	}
	
	protected function getTable()
	{
		return $this->connection->table('package');
	}
	
	/*
	 *vrátí packages podle zadaného parametru (pole) 
	 *return PackageDomain
	 */
	public function searchPackageByRefPackage(array $refpackage)
	{
		$rows = $this->getTable()->where('serno', $refpackage)->fetch();
		foreach ($rows as $row){
			return new PackageDomain($row->toArray());
		}
	}
	
	/*
	 *vrátí packages podle zadaného parametru (pole) 
	 */
	public function searchPackageByPostingNumber(array $postingnumber)
	{
		$rows = $this->getTable()->where('postingnumber', $postingnumber)->fetch();
		foreach ($rows as $row){
			return new PackageDomain($row->toArray());
		}
	}
	
	//uloží package TODO
	public function savePackage($form)
	{
		 $row = $this->getTable()->insert($form);
		 return $row->serno;
	}
	
 }